home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / glyphs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-15  |  15.8 KB  |  440 lines

  1. /* Generic glyph data structures + display tables
  2.    Copyright (C) 1994 Board of Trustees, University of Illinois
  3.    Copyright (C) 1995 Ben Wing
  4.  
  5. This file is part of XEmacs.
  6.  
  7. XEmacs is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. XEmacs is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with XEmacs; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /* Synched up with: Not in FSF. */
  22.  
  23. #ifndef _XEMACS_GLYPHS_H_
  24. #define _XEMACS_GLYPHS_H_
  25.  
  26. #include "specifier.h"
  27.  
  28. /*****************************************************************************
  29.  *                            Image Instantiators                            *
  30.  *****************************************************************************/
  31.  
  32. struct image_instantiator_methods;
  33.  
  34. /* Note that image-instance types are not the same as image-instantiator types.
  35.    Here's an approximate mapping:
  36.  
  37.   image type                image-instantiator type
  38.   ----------                -----------------------
  39.   nothing                nothing
  40.   string                text
  41.   formatted-string            text
  42.   xbm                    mono-pixmap or cursor
  43.   xpm                    color-pixmap, mono-pixmap, or cursor
  44.   xface                    mono-pixmap or cursor
  45.   cursor-font                cursor
  46.   subwindow                subwindow
  47.  
  48. */
  49.  
  50. enum image_instance_type
  51. {
  52.   IMAGE_UNKNOWN,
  53.   IMAGE_NOTHING,
  54.   IMAGE_TEXT,
  55.   IMAGE_MONO_PIXMAP,
  56.   IMAGE_COLOR_PIXMAP,
  57.   IMAGE_CURSOR,
  58.   IMAGE_SUBWINDOW
  59. };
  60.  
  61. #define IMAGE_NOTHING_MASK (1 << 0)
  62. #define IMAGE_TEXT_MASK (1 << 1)
  63. #define IMAGE_MONO_PIXMAP_MASK (1 << 2)
  64. #define IMAGE_COLOR_PIXMAP_MASK (1 << 3)
  65. #define IMAGE_CURSOR_MASK (1 << 4)
  66. #define IMAGE_SUBWINDOW_MASK (1 << 5)
  67.  
  68. typedef struct ii_keyword_entry_dynarr_type
  69. {
  70.   Dynarr_declare (struct ii_keyword_entry);
  71. } Ii_keyword_entry_dynarr;
  72.  
  73. /* These are methods specific to a particular type of image instantiator
  74.    (e.g. xpm, string, etc.). */
  75.  
  76. struct image_instantiator_methods
  77. {
  78.   Lisp_Object symbol;
  79.  
  80.   Ii_keyword_entry_dynarr *keywords;
  81.   /* Implementation specific methods: */
  82.  
  83.   /* Validate method: Given an instantiator vector, return non-zero if
  84.      it's valid for this image-instantiator type, zero otherwise.
  85.      Note that this validation only occurs after all the keyword-
  86.      specific validation has already been performed.  This is chiefly
  87.      useful for making sure that certain required keywords are
  88.      present.  If NO_ERROR is zero, the validation method can signal
  89.      an error if the instantiator is invalid. (This is so that a more
  90.      explanatory error message can be issued.) Even if NO_ERROR is
  91.      zero, however, this function can go ahead and return 0 for an
  92.      invalid instantiator. (In that case, the caller gets a generic
  93.      error message "Invalid instantiator".). */
  94.   int (*validate_method) (Lisp_Object instantiator, int no_error);
  95.  
  96.   /* Normalize method: Given an instantiator, convert it to the form
  97.      that should be used in a glyph, for devices of type DEVICE_TYPE.
  98.      Return Qnil if the conversion fails. */
  99.   Lisp_Object (*normalize_method) (Lisp_Object instantiator,
  100.                    Lisp_Object device_type,
  101.                    int no_error);
  102.  
  103.   /* Instantiate method: Given an instantiator and a partially
  104.      filled-in image instance, complete the filling-in.  Return
  105.      non-zero if the instantiation succeeds, 0 if it fails.
  106.      This must be present. */
  107.   int (*instantiate_method) (Lisp_Object image_instance,
  108.                  Lisp_Object instantiator,
  109.                  int dest_mask,
  110.                  int no_error);
  111. };
  112.  
  113. struct ii_keyword_entry
  114. {
  115.   Lisp_Object keyword;
  116.   int (*validate) (Lisp_Object data, int no_error);
  117.   int multiple_p;
  118. };
  119.  
  120. /***** Calling an image-instantiator method *****/
  121.  
  122. #define HAS_IITYPE_METH_P(mstruc, m) ((mstruc)->m##_method)
  123. #define IITYPE_METH(mstruc, m, args) (((mstruc)->m##_method) args)
  124.  
  125. /* Call a void-returning specifier method, if it exists */
  126. #define MAYBE_IITYPE_METH(mstruc, m, args)                   \
  127. do {                                       \
  128.   struct image_instantiator_methods *_maybe_iitype_meth_mstruc = (mstruc); \
  129.   if (HAS_IITYPE_METH_P (_maybe_iitype_meth_mstruc, m))               \
  130.     IITYPE_METH (_maybe_iitype_meth_mstruc, m, args);               \
  131. } while (0)
  132.  
  133. MAC_DECLARE_EXTERN (struct image_instantiator_methods *,
  134.             mactemp_iitype_meth_or_given)
  135.  
  136. /* Call a specifier method, if it exists; otherwise return
  137.    the specified value */
  138.  
  139. #define IITYPE_METH_OR_GIVEN(mstruc, m, args, given)            \
  140. MAC_BEGIN                                \
  141.   MAC_DECLARE (struct image_instantiator_methods *,            \
  142.            mactemp_iitype_meth_or_given, mstruc)            \
  143.   HAS_IITYPE_METH_P (mactemp_iitype_meth_or_given, m) ?            \
  144.     IITYPE_METH (mactemp_iitype_meth_or_given, m, args) : (given)    \
  145. MAC_END
  146.  
  147. /***** Defining new image-instantiator types *****/
  148.  
  149. #define DECLARE_IMAGE_INSTANTIATOR_TYPE(type)                     \
  150. extern struct image_instantiator_methods * type##_image_instantiator_methods
  151.  
  152. #define DEFINE_IMAGE_INSTANTIATOR_TYPE(type)                \
  153. struct image_instantiator_methods * type##_image_instantiator_methods
  154.  
  155. #define INITIALIZE_IMAGE_INSTANTIATOR_TYPE(type, obj_name)    \
  156.   do {                                \
  157.     type##_image_instantiator_methods =                \
  158.       malloc_type_and_zero (struct image_instantiator_methods);    \
  159.     defsymbol (&Q##type, obj_name);                \
  160.     type##_image_instantiator_methods->symbol = Q##type;    \
  161.     type##_image_instantiator_methods->keywords =        \
  162.       Dynarr_new (struct ii_keyword_entry);            \
  163.     add_entry_to_image_instantiator_type_list            \
  164.       (Q##type, type##_image_instantiator_methods);        \
  165.   } while (0)
  166.  
  167. /* Declare that image-instantiator type TYPE has method M; used in
  168.    initialization routines */
  169. #define IITYPE_HAS_METHOD(type, m) \
  170.   (type##_image_instantiator_methods->m##_method = type##_##m)
  171.  
  172. /* Declare that KEYW is a valid keyword for image-instantiator type
  173.    TYPE.  VALIDATE_FUN if a function that returns whether the data
  174.    is valid.  The keyword may not appear more than once. */
  175. #define IITYPE_VALID_KEYWORD(type, keyw, validate_fun)        \
  176.   do {                                \
  177.     struct ii_keyword_entry entry;                \
  178.                                 \
  179.     entry.keyword = keyw;                    \
  180.     entry.validate = validate_fun;                \
  181.     entry.multiple_p = 0;                    \
  182.     Dynarr_add (type##_image_instantiator_methods->keywords,    \
  183.         entry);                        \
  184.   } while (0)
  185.  
  186. /* Same as IITYPE_VALID_KEYWORD except that the keyword may
  187.    appear multiple times. */
  188. #define IITYPE_VALID_MULTI_KEYWORD(type, keyword, validate_fun)    \
  189.   do {                                \
  190.     struct ii_keyword_entry entry;                \
  191.                                 \
  192.     entry.keyword = keyword;                    \
  193.     entry.validate = validate_fun;                \
  194.     entry.multiple_p = 1;                    \
  195.     Dynarr_add (type##_image_instantiator_methods->keywords,    \
  196.         entry);                        \
  197.   } while (0)
  198.  
  199. extern Lisp_Object Q_data, Q_file, Qautodetect;
  200.  
  201. extern void add_entry_to_image_instantiator_type_list (Lisp_Object symbol,
  202.             struct image_instantiator_methods *meths);
  203. extern Lisp_Object find_keyword_in_vector (Lisp_Object vector,
  204.                        Lisp_Object keyword);
  205. extern Lisp_Object find_keyword_in_vector_or_given (Lisp_Object vector,
  206.                             Lisp_Object keyword,
  207.                             Lisp_Object defalt);
  208. extern int valid_string_p (Lisp_Object data, int no_error);
  209. extern int valid_int_p (Lisp_Object data, int no_error);
  210.  
  211. /*****************************************************************************
  212.  *                          Image Specifier Object                           *
  213.  *****************************************************************************/
  214.  
  215. DECLARE_SPECIFIER_TYPE (image);
  216. extern Lisp_Object Qimage;
  217. #define XIMAGE_SPECIFIER(x) XSPECIFIER_TYPE (x, image)
  218. #define XSETIMAGE_SPECIFIER(x, p) XSETSPECIFIER_TYPE (x, p, image)
  219. #define IMAGE_SPECIFIERP(x) SPECIFIER_TYPEP (x, image)
  220. #define CHECK_IMAGE_SPECIFIER(x, i) CHECK_SPECIFIER_TYPE (x, i, image)
  221.  
  222. extern void set_image_attached_to (Lisp_Object obj, Lisp_Object face,
  223.                    Lisp_Object property);
  224.  
  225. struct image_specifier
  226. {
  227.   int allowed;
  228.   Lisp_Object face;        /* face this is attached to, or nil */
  229.   Lisp_Object face_property;    /* property of that face */
  230. };
  231.  
  232. #define IMAGE_SPECIFIER_DATA(g) (SPECIFIER_TYPE_DATA (g, image))
  233. #define IMAGE_SPECIFIER_ALLOWED(g) (IMAGE_SPECIFIER_DATA (g)->allowed)
  234. #define IMAGE_SPECIFIER_FACE(g) (IMAGE_SPECIFIER_DATA (g)->face)
  235. #define IMAGE_SPECIFIER_FACE_PROPERTY(g) \
  236.   (IMAGE_SPECIFIER_DATA (g)->face_property)
  237.  
  238. #define XIMAGE_SPECIFIER_ALLOWED(g) \
  239.   IMAGE_SPECIFIER_ALLOWED (XIMAGE_SPECIFIER (g))
  240. /*****************************************************************************
  241.  *                           Image Instance Object                           *
  242.  *****************************************************************************/
  243.  
  244. DECLARE_LRECORD (image_instance, struct Lisp_Image_Instance);
  245. #define XIMAGE_INSTANCE(x) \
  246.   XRECORD (x, image_instance, struct Lisp_Image_Instance)
  247. #define XSETIMAGE_INSTANCE(x, p) XSETRECORD (x, p, image_instance)
  248. #define IMAGE_INSTANCEP(x) RECORDP (x, image_instance)
  249. #define CHECK_IMAGE_INSTANCE(x, i) CHECK_RECORD (x, image_instance)
  250.  
  251. struct Lisp_Image_Instance
  252. {
  253.   struct lcrecord_header header;
  254.   Lisp_Object device;
  255.   Lisp_Object name;
  256.   enum image_instance_type type;
  257.   union
  258.     {
  259.       struct
  260.     {
  261.       Lisp_Object string;
  262.     } text;
  263.       struct
  264.     {
  265.       int width, height, depth;
  266.       Lisp_Object hotspot_x, hotspot_y; /* integer or Qnil */
  267.       Lisp_Object filename; /* string or Qnil */
  268.       Lisp_Object mask_filename; /* string or Qnil */
  269.     } pixmap;
  270.       struct
  271.     {
  272.       int dummy; /* #### fill in this structure */
  273.     } subwindow;
  274.     } u;
  275.  
  276.   /* device-type- and image-type-specific data */
  277.   void *data;
  278. };
  279.  
  280. #define IMAGE_INSTANCE_DEVICE(i) ((i)->device)
  281. #define IMAGE_INSTANCE_NAME(i) ((i)->name)
  282. #define IMAGE_INSTANCE_TYPE(i) ((i)->type)
  283. #define IMAGE_INSTANCE_PIXMAP_TYPE_P(i)                    \
  284.  ((IMAGE_INSTANCE_TYPE (i) == IMAGE_MONO_PIXMAP)            \
  285.   || (IMAGE_INSTANCE_TYPE (i) == IMAGE_COLOR_PIXMAP))
  286.  
  287. #define IMAGE_INSTANCE_TEXT_STRING(i) ((i)->u.text.string)
  288.  
  289. #define IMAGE_INSTANCE_PIXMAP_WIDTH(i) ((i)->u.pixmap.width)
  290. #define IMAGE_INSTANCE_PIXMAP_HEIGHT(i) ((i)->u.pixmap.height)
  291. #define IMAGE_INSTANCE_PIXMAP_DEPTH(i) ((i)->u.pixmap.depth)
  292. #define IMAGE_INSTANCE_PIXMAP_FILENAME(i) ((i)->u.pixmap.filename)
  293. #define IMAGE_INSTANCE_PIXMAP_MASK_FILENAME(i) ((i)->u.pixmap.mask_filename)
  294. #define IMAGE_INSTANCE_PIXMAP_HOTSPOT_X(i) ((i)->u.pixmap.hotspot_x)
  295. #define IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y(i) ((i)->u.pixmap.hotspot_y)
  296.  
  297. #define XIMAGE_INSTANCE_DEVICE(i) \
  298.   IMAGE_INSTANCE_DEVICE (XIMAGE_INSTANCE (i))
  299. #define XIMAGE_INSTANCE_NAME(i) \
  300.   IMAGE_INSTANCE_NAME (XIMAGE_INSTANCE (i))
  301. #define XIMAGE_INSTANCE_TYPE(i) \
  302.   IMAGE_INSTANCE_TYPE (XIMAGE_INSTANCE (i))
  303.  
  304. #define XIMAGE_INSTANCE_TEXT_STRING(i) \
  305.   IMAGE_INSTANCE_TEXT_STRING (XIMAGE_INSTANCE (i))
  306.  
  307. #define XIMAGE_INSTANCE_PIXMAP_WIDTH(i) \
  308.   IMAGE_INSTANCE_PIXMAP_WIDTH (XIMAGE_INSTANCE (i))
  309. #define XIMAGE_INSTANCE_PIXMAP_HEIGHT(i) \
  310.   IMAGE_INSTANCE_PIXMAP_HEIGHT (XIMAGE_INSTANCE (i))
  311. #define XIMAGE_INSTANCE_PIXMAP_DEPTH(i) \
  312.   IMAGE_INSTANCE_PIXMAP_DEPTH (XIMAGE_INSTANCE (i))
  313. #define XIMAGE_INSTANCE_PIXMAP_FILENAME(i) \
  314.   IMAGE_INSTANCE_PIXMAP_FILENAME (XIMAGE_INSTANCE (i))
  315. #define XIMAGE_INSTANCE_PIXMAP_MASK_FILENAME(i) \
  316.   IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (XIMAGE_INSTANCE (i))
  317. #define XIMAGE_INSTANCE_PIXMAP_HOTSPOT_X(i) \
  318.   IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (XIMAGE_INSTANCE (i))
  319. #define XIMAGE_INSTANCE_PIXMAP_HOTSPOT_Y(i) \
  320.   IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (XIMAGE_INSTANCE (i))
  321.  
  322. /*****************************************************************************
  323.  *                              Glyph Object                                 *
  324.  *****************************************************************************/
  325.  
  326. enum glyph_type
  327. {
  328.   GLYPH_UNKNOWN,
  329.   GLYPH_BUFFER,
  330.   GLYPH_CURSOR,
  331.   GLYPH_ICON
  332. };
  333.  
  334. struct Lisp_Glyph
  335. {
  336.   struct lcrecord_header header;
  337.  
  338.   enum glyph_type type;
  339.  
  340.   /* specifiers: */
  341.   Lisp_Object image;        /* the actual image */
  342.   Lisp_Object contrib_p;    /* whether to figure into line height */
  343.   Lisp_Object baseline;        /* percent above baseline */
  344.  
  345.   Lisp_Object face;        /* if non-nil, face to use when displaying */
  346.  
  347.   Lisp_Object plist;
  348. };
  349.  
  350. DECLARE_LRECORD (glyph, struct Lisp_Glyph);
  351. #define XGLYPH(x) XRECORD (x, glyph, struct Lisp_Glyph)
  352. #define XSETGLYPH(x, p) XSETRECORD (x, p, glyph)
  353. #define GLYPHP(x) RECORDP (x, glyph)
  354. #define CHECK_GLYPH(x, i) CHECK_RECORD (x, glyph)
  355.  
  356. #define GLYPH_TYPE(g) ((g)->type)
  357. #define GLYPH_IMAGE(g) ((g)->image)
  358. #define GLYPH_CONTRIB_P(g) ((g)->contrib_p)
  359. #define GLYPH_BASELINE(g) ((g)->baseline)
  360. #define GLYPH_FACE(g) ((g)->face)
  361.  
  362. #define XGLYPH_TYPE(g) GLYPH_TYPE (XGLYPH (g))
  363. #define XGLYPH_IMAGE(g) GLYPH_IMAGE (XGLYPH (g))
  364. #define XGLYPH_CONTRIB_P(g) GLYPH_CONTRIB_P (XGLYPH (g))
  365. #define XGLYPH_BASELINE(g) GLYPH_BASELINE (XGLYPH (g))
  366. #define XGLYPH_FACE(g) GLYPH_FACE (XGLYPH (g))
  367.  
  368. extern Lisp_Object Vtruncation_glyph, Vcontinuation_glyph, Voctal_escape_glyph;
  369. extern Lisp_Object Vcontrol_arrow_glyph, Vinvisible_text_glyph, Vhscroll_glyph;
  370. extern Lisp_Object Vxemacs_logo;
  371.  
  372. extern unsigned short glyph_width (Lisp_Object glyph, face_index findex,
  373.                    int framep, Lisp_Object window);
  374. extern unsigned short glyph_ascent (Lisp_Object glyph, face_index findex,
  375.                     int framep, Lisp_Object window);
  376. extern unsigned short glyph_descent (Lisp_Object glyph, face_index findex,
  377.                      int framep, Lisp_Object window);
  378. extern unsigned short glyph_height (Lisp_Object glyph, face_index findex,
  379.                     int framep, Lisp_Object window);
  380. extern Lisp_Object glyph_baseline (Lisp_Object glyph, Lisp_Object domain);
  381. extern Lisp_Object glyph_face (Lisp_Object glyph, Lisp_Object domain);
  382. extern int glyph_contrib_p (Lisp_Object glyph, Lisp_Object domain);
  383. extern Lisp_Object glyph_image_instance (Lisp_Object glyph,
  384.                      Lisp_Object domain,
  385.                      int no_error_or_quit);
  386. extern int file_or_data_must_be_present (Lisp_Object instantiator,
  387.                      int no_error);
  388. extern int data_must_be_present (Lisp_Object instantiator, int no_error);
  389. extern Lisp_Object make_string_from_file (Lisp_Object file);
  390. extern Lisp_Object tagged_vector_to_alist (Lisp_Object vector);
  391. extern Lisp_Object alist_to_tagged_vector (Lisp_Object tag, Lisp_Object alist);
  392.  
  393. /*****************************************************************************
  394.  *                          Glyph Cache Elements                             *
  395.  *****************************************************************************/
  396.  
  397. struct glyph_cache_element
  398. {
  399.   Lisp_Object glyph;
  400.  
  401.   unsigned int updated :1;
  402.   unsigned short width;
  403.   unsigned short ascent;
  404.   unsigned short descent;
  405. };
  406.  
  407. #define CONT_GLYPH_INDEX    (glyph_index) 0
  408. #define TRUN_GLYPH_INDEX    (glyph_index) 1
  409. #define HSCROLL_GLYPH_INDEX    (glyph_index) 2
  410. #define CONTROL_GLYPH_INDEX    (glyph_index) 3
  411. #define OCT_ESC_GLYPH_INDEX    (glyph_index) 4
  412. #define INVIS_GLYPH_INDEX    (glyph_index) 5
  413.  
  414. #define GLYPH_CACHE_ELEMENT(window, index)                \
  415.   Dynarr_atp (window->glyph_cache_elements, index)
  416. #define GLYPH_CACHE_ELEMENT_GLYPH(window, index)            \
  417.   Dynarr_atp (window->glyph_cache_elements, index)->glyph
  418. #define GLYPH_CACHE_ELEMENT_WIDTH(window, index)            \
  419.   Dynarr_atp (window->glyph_cache_elements, index)->width
  420. #define GLYPH_CACHE_ELEMENT_ASCENT(window, index)            \
  421.   Dynarr_atp (window->glyph_cache_elements, index)->ascent
  422. #define GLYPH_CACHE_ELEMENT_DESCENT(window, index)            \
  423.   Dynarr_atp (window->glyph_cache_elements, index)->descent
  424.  
  425. extern void mark_glyph_cache_elements (glyph_cache_element_dynarr *elements,
  426.                        void (*markobj) (Lisp_Object));
  427. extern void mark_glyph_cache_elements_as_not_updated (struct window *w);
  428. extern void reset_glyph_cache_elements (struct window *w);
  429.  
  430. /*****************************************************************************
  431.  *                             Display Tables                                *
  432.  *****************************************************************************/
  433.  
  434. #define DISP_TABLE_SIZE    256
  435. #define DISP_CHAR_ENTRY(dp, c)    ((dp)->contents[c])
  436.  
  437. extern struct Lisp_Vector *get_display_table (struct window *, face_index);
  438.  
  439. #endif /* _XEMACS_GLYPHS_H_ */
  440.